<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 暴力解法 双循环
        var lengthOfLongestSubstring = function (s) {
            let n = s.length;
            let left = 0,
                right = 0;
            let set = new Array();
            let maxLength = 0;
            let index = 0;

            while (right < n) {
                index = set.indexOf(s.charAt(right))
                if (index == -1) {
                    set.push(s.charAt(right));
                } else {
                    set.push(s.charAt(right));
                    set.splice(0, index + 1);
                }
                maxLength = Math.max(maxLength, set.length);
                right++;
            }
            return maxLength;
        };

        console.log(lengthOfLongestSubstring("bbbbb"));
    </script>
</body>

</html>